﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XcoAppSpaces.Contracts.Communication;
using XcoAppSpaces.Contracts.Transport;
using XcoAppSpaces.Contracts.WorkerResolve;

namespace XcoAppSpaces.Core.Communication
{
	class CommunicationEvents : ICommunicationEvents
	{
		public event Action<MessageEventArgs> OnMessageReceived;
		public event Action<MessageEventArgs> OnSendingMessage;

		public void RaiseOnSendingMessageEvent(XcoMessage msg, string remoteAddress, string transportServiceName)
		{
			if (OnSendingMessage != null)
				OnSendingMessage(new MessageEventArgs { Message = msg, Address = remoteAddress, TransportServiceName = transportServiceName });
		}
		public void RaiseOnMessageReceivedEvent(XcoMessage msg, string remoteAddress, string transportServiceName)
		{
			if (OnMessageReceived != null)
				OnMessageReceived(new MessageEventArgs { Message = msg, Address = remoteAddress, TransportServiceName = transportServiceName });
		}


		public event Action<WorkerResolveEventArgs> OnWorkerResolved;

		public void RaiseOnWorkerResolvedEvent(string workerIdentifier, string remoteAddress, ResolveStatus result)
		{
			if (OnWorkerResolved != null)
				OnWorkerResolved(new WorkerResolveEventArgs { WorkerIdentifier = workerIdentifier, RemoteAddress = remoteAddress, Result = result });
		}
	}
}
